using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP.Classes;

namespace ERP.View
{
    public partial class viewPhanquyenMenu : DevExpress.XtraEditors.XtraForm
    {
        public viewPhanquyenMenu()
        {
            InitializeComponent();
        }

        //public cs_hmr_userrightInfo userright = new cs_hmr_userrightInfo();
        public cs_hmr_usersInfo user = new cs_hmr_usersInfo();
        public cs_hmr_nhom_nguoi_dungInfo nhom = new cs_hmr_nhom_nguoi_dungInfo();
        public cs_hmr_menurightInfo mnuright = new cs_hmr_menurightInfo();
        public int count = 0;

        private void cboNhom_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void viewPhanquyenMenu_Load(object sender, EventArgs e)
        {
            this.cboNhom.Properties.DataSource = this.nhom.Get_List().Tables[0];
            this.CheckUser();
        }

        private void CheckUser()
        {
            cs_hmr_userrightInfo userright = new cs_hmr_userrightInfo();
            userright.groupid = this.user.groupid;
            cs_hmr_winformInfo wf = new cs_hmr_winformInfo();
            wf.tenform = this.Name;
            if (wf.Get_Info() > 0)
            {
                userright.form_id = wf.formid;
                userright.Get_Info();
                if (userright.savedata == 0)
                {
                    this.btnLuu.Enabled = false;
                }
                if (userright.deletedata == 0)
                {
                }
                if (userright.updatedata == 0)
                {
                    this.btnLuu.Enabled = false;
                }
                if (userright.printreport == 0)
                {
                }
            }
        }

        private void cboNhom_EditValueChanged(object sender, EventArgs e)
        {
            
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            int k = 0;
            for (int i = 0; i < this.count; i++)
            {
                this.mnuright.menuid = int.Parse(this.gridView1.GetRowCellValue(i, gridColumn1).ToString().Trim());
                this.mnuright.enable_status = Convert.ToBoolean(this.gridView1.GetRowCellValue(i, gridColumn4).ToString().Trim());
                k += this.mnuright.ExcuteProcedure(2);
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose(true);
        }

        private void cboNhom_EditValueChanged_1(object sender, EventArgs e)
        {
            this.mnuright.groupid = int.Parse(this.cboNhom.EditValue.ToString().Trim());
            DataSet ds = new DataSet("ds");
            ds = this.mnuright.Get_List();
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {
                this.count = 0;
            }
            else
            {
                this.grdManhinh.DataSource = ds.Tables[0];
                this.count = ds.Tables[0].Rows.Count;
                //this.repositoryItemCheckEdit1.
            }
        }
    }
}